//
//  SetHttpViewController.m
//  shoubao_user
//
//  Created by xiao_shoubao on 16/9/1.
//  Copyright © 2016年 xiao_shoubao. All rights reserved.
//

#import "TestHttpViewController.h"
#import "ConfigTest.h"


typedef void(^TextCompleteDelayBlock)();

@interface TestHttpViewController ()
@end

@implementation TestHttpViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.title = @"设置链接";
    self.texthttp.text = HTTPAPI;
    self.textimagehttp .text = HTTPIMAGE;
    
    self.http.text = HTTPAPI;
    self.imagehttp.text = HTTPIMAGE;
    
    self.version.text = kVersion;
    self.textversion.text = kVersion;
    
    [self addRightBarButton:@"恢复默认"];
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}



- (void)clickRightBarButton:(UIButton *)sender{
    
    [ConfigTest updateHTTP:@"http://"];
    [ConfigTest updateImageHTTP:@"http://"];
    [ConfigTest updateVersion:kVersionPublic];
    
    [self delayBlock:^{
        
        self.http.text = HTTPAPI;
        self.imagehttp.text = HTTPIMAGE;
        self.texthttp.text = HTTPAPI;
        self.textimagehttp.text = HTTPIMAGE;
        self.version.text = kVersion;
        self.textversion.text = kVersion;
        
    }];
}

- (IBAction)ClickHttp:(id)sender {
    
    [ConfigTest updateHTTP:self.http.text];
    
    [self delayBlock:^{
        self.texthttp.text = HTTPAPI;
    }];
    
}

///  固定链接------------------------------
- (IBAction)ClickHttpYM:(id)sender {
    
    [ConfigTest updateHTTP:@"http://"];
    
    [self delayBlock:^{
        self.texthttp.text = HTTPAPI;
        self.http.text = HTTPAPI;
    }];

    
}

- (IBAction)ClickHttp216:(id)sender {
    
    [ConfigTest updateHTTP:@"http://"];
    
    [self delayBlock:^{
        self.texthttp.text = HTTPAPI;
        self.http.text = HTTPAPI;
    }];

}

- (IBAction)ClickHttp88:(id)sender {
    
    [ConfigTest updateHTTP:@"http://"];
    
    [self delayBlock:^{
        self.texthttp.text = HTTPAPI;
        self.http.text = HTTPAPI;
    }];
    

}

- (IBAction)ClickHttp60:(id)sender {
    
    [ConfigTest updateHTTP:@"http://"];
    
    [self delayBlock:^{
        self.texthttp.text = HTTPAPI;
        self.http.text = HTTPAPI;
    }];
}

///  图片链接------------------------------
- (IBAction)ClickImageHttp:(id)sender {
    
    [ConfigTest updateImageHTTP:self.imagehttp.text];
    
    [self delayBlock:^{
        self.textimagehttp.text = HTTPIMAGE;
    }];
}

///  版本号设置 ------------------------------
- (IBAction)ClickVersion:(id)sender{
    
    [ConfigTest updateVersion:self.version.text];
    
    [self delayBlock:^{
        self.textversion.text = kVersion;
    }];

}


- (void)delayBlock:(TextCompleteDelayBlock)block{
    
    double delayInSeconds = 0.3;
    dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, (int64_t)(delayInSeconds * NSEC_PER_SEC));
    dispatch_after(popTime, dispatch_get_main_queue(), ^(void){
        
        block();
        
    });
}
@end
